package com.sbp.message.api.entity;

import java.io.Serializable;

public enum MessageStatus implements Serializable {
    unconfirmed(0, "待确认"),
    confirmed(1, "确认未发送"),
    sending(2, "发送中"),
    dead(3, "死亡"),
    end(4, "发送成功");
    protected static final MessageStatus defaultEnum = unconfirmed;

    protected final int value;
    protected final String desc;
    MessageStatus(int value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    public int getValue() {
        return this.value;
    }
    public String getDesc() {
        return desc;
    }

    public static int getValue(MessageStatus status) {
        if (status == null)
            return defaultEnum.value;
        else
            return status.value;
    }

    public static MessageStatus valueOf(int value, boolean returnDefault) {
        MessageStatus[] list = MessageStatus.values();
        for (int i=0; i<list.length; ++i) {
            if (list[i].value == value)
                return list[i];
        }

        if (returnDefault)
            return defaultEnum;
        else
            return null;
    }
}
